package test;

import java.util.HashMap;

import com.cloopen.rest.sdk.CCPRestSDK;
import com.cloopen.rest.sdk.CCPRestSmsSDK;

public class TestRongly {

	public static void main(String[] args) {
		String appkey = "8aaf070858a8910b0158a8fa50460179";
		String secret = "254c1d83d5f64888875ab972bc4d4a80";
		String appid="8aaf070858f612040158f6e307a00147";
		String code = "5678";
		String tel = "15001236918";//13621290013
		String extend = "12345";
		
		TestRongly test=new TestRongly();
		boolean b1= test.sendCodeVoice(appkey, secret, appid, code, tel, extend, "");
		boolean b2 =test.sendCodeSms(appkey, secret, appid, tel, "143421", code);
		boolean b3 =test.sendSms(appkey, secret, appid, tel, "143324", new String[]{"h16","2016-12-20 10:10:10","开发者网站许可操作相关测试"});
		System.out.println(b1 +"  "+b2+"   "+b3);
	}

	
	private String url = "app.cloopen.com";
	private String port = "8883";

	public boolean sendCodeSms(String appkey, String secret, String appid, String tel, String template, String code) {
		boolean b=false;
		CCPRestSmsSDK restAPI = new CCPRestSmsSDK();
		restAPI.init(url, port);
		restAPI.setAccount(appkey, secret);
		restAPI.setAppId(appid);
		HashMap<String, Object> result = restAPI.sendTemplateSMS(tel, template, new String[] { code, "5" });
		if ("000000".equals(result.get("statusCode"))) {
			b=true;
		} else {
		}
		return b;
	}

	public boolean sendCodeVoice(String appkey, String secret, String appid, String code, String tel, String extend,
			String showNum) {
		boolean b=false;
		CCPRestSDK restAPI = new CCPRestSDK();
		restAPI.init(url, port);
		restAPI.setAccount(appkey, secret);
		restAPI.setAppId(appid);
		HashMap<String, Object> result = restAPI.voiceVerify(code, tel, showNum, "3", "", "zh", extend, "", "");
		if ("000000".equals(result.get("statusCode"))) {
			b=true;
		} else {
		}
		return b;
	}

	public boolean sendSms(String appkey, String secret, String appid, String tel, String template, String[] txtary) {
		boolean b=false;
		CCPRestSmsSDK restAPI = new CCPRestSmsSDK();
		restAPI.init(url, port);
		restAPI.setAccount(appkey, secret);
		restAPI.setAppId(appid);
		HashMap<String, Object> result = restAPI.sendTemplateSMS(tel, template, txtary);
		if ("000000".equals(result.get("statusCode"))) {
			b=true;
		} else {
		}
		return b;
	}
}
